package com.tarena.sentinel.study.demo02.controller;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tarena.sentinel.study.demo02.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class HelloController {
    @Autowired
    private HelloService helloService;
    /**
     * 接收测试请求的接口功能
     * http://localhost:8080/hello?name=王翠花
     * hello sentinel i am 王翠花
     */
    @GetMapping("/hello")
    @SentinelResource(value="app",blockHandler="appBlock")
    public String sayHi(String name) throws InterruptedException {
        System.out.println(helloService.getClass().getName());
        String result=null;
        Thread.sleep(150);
        result=helloService.sayHi(name);
        return result;
    }
    public String appBlock(String name,BlockException e){
        log.info("当前app资源 被熔断了,持续10秒");
        return "请求资源被熔断处理了";
    }
}













